﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IntraVision.Web;

namespace Model
{
    public interface IClient
    {
        int Id { get; }
        string Name { get; }
        string IdStr { get; }
        string TypeName { get; }
        int Cid { get; }
        bool IsCashless { get; }
        bool IsNotify { get; }
        string NotifyComment { get; }
    }

    public partial class Client
    {
        public string Type
        {
            get { return (this.IsNatural) ? "person" : "company"; }
        }

        public string IdStr
        {
            get { return String.Concat((this.IsNatural) ? "p" : "c", this.Id); }
        }

        public int Cid
        {
            get { return this.Id * 10 + Convert.ToInt32(this.IsNatural); }
        }

        public static bool CheckIsNatural(int cid)
        {
            return Convert.ToBoolean(0x1 & cid);
        }

        public static int GetIdByCid(int cid)
        {
            return cid / 10;
        }

        public static string GetTypeByCid(int cid)
        {
            return (CheckIsNatural(cid)) ? "person": "company";
        }

        public static string GetLinkByCid(int cid)
        {
            return String.Format("{0}.ivp/view/{1}", (Client.CheckIsNatural(cid) ? "person" : "company"), Client.GetIdByCid(cid));
        }
    }
}
